<template>
  <!-- 雷达图  图表必须给高和宽度-->
  <div ref="myDiv" class="radar-echart" />
</template>

<script>
// commonJS 按需加载
const echarts = require('echarts/lib/echarts') // 引入echarts主模块
require('echarts/lib/chart/radar') // 引入雷达图
// 引入提示框和标题组件
require('echarts/lib/component/tooltip')
require('echarts/lib/component/title')
export default {
  data() {
    return {
      radarData: []
    }
  },
  async mounted() {
    await this.getRadarData()
    this.getRadarEchart()
  },
  methods: {
    // 雷达图数据api
    radarDataApi() {
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          // 数据库得到的数据
          const data = [
            {
              value: [100, 11, 100, 5, 100, 0],
              name: '张三'
            },
            {
              value: [100, 51, 50, 50, 50, 10],
              name: '李四'
            }
          ]
          // 返回出去
          resolve(data)
        }, 0)
      })
    },
    // 获取雷达图数据
    async getRadarData() {
      this.radarData = await this.radarDataApi()
    },

    getRadarEchart() {
      const myChart = echarts.init(this.$refs.myDiv) // 得到图表实例
      const options = {
        title: {
          text: '员工效率图'
        },
        tooltip: {},
        radar: {
          name: {
            textStyle: {
              color: '#fff',
              backgroundColor: '#999',
              borderRadius: 3,
              padding: [3, 5]
            }
          },
          // 每个区域的最高值
          indicator: [
            { name: '工作效率', max: 100 },
            { name: '考勤', max: 100 },
            { name: '积极性', max: 100 },
            { name: '帮助同事', max: 100 },
            { name: '自主学习', max: 100 },
            { name: '正确率', max: 100 }
          ]
        },
        series: [
          {
            type: 'radar',
            data: this.radarData
          }
        ]
      }
      myChart.setOption(options)
    }
  }
}
</script>

<style lang="scss" scoped>
.radar-echart {
  width: 600px;
  height: 400px;
}
</style>
